package com.hubing.cloud.app.web.model;

/**
 * JSON返回数据编码定义
 */
public class CodeMsg {

    private int code;

    private String msg;

    public static CodeMsg SUCCESS = new CodeMsg(0, "success");

    /**
     * 通用的错误码
     */
    public static CodeMsg DEFINE_ERROR = new CodeMsg(500000, "%s");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常");
    public static CodeMsg UNAUTHORIZED = new CodeMsg(500101, "没有访问权限！");
    public static CodeMsg BIND_ERROR = new CodeMsg(500102, "参数校验异常：%s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500103, "请求非法");
    public static CodeMsg ACCESS_LIMIT_REACHED = new CodeMsg(500104, "访问太频繁！");
    public static CodeMsg VERIFY_FAILE = new CodeMsg(500105, "操作太频繁或已达到上限");
    public static CodeMsg OVER_TIME = new CodeMsg(500106, "超时");
    public static CodeMsg BIND_CANNOT_NULL = new CodeMsg(500107,"参数不可为空");
    public static CodeMsg PARAM_MISS_STATION = new CodeMsg(500108,"接种点编码有误");
    public static CodeMsg PARAM_MISS = new CodeMsg(500109,"参数丢失");
    public static CodeMsg MISS_BUTTON_PERMISSION = new CodeMsg(500110,"您没有维护权限");

    // xxx模块 500XXX  e.g. public static CodeMsg MODULE_ACTION = new CodeMsg(500XXX, "XXXX")


    public CodeMsg(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }

}
